package com.grj.park.boot.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.grj.park.boot.domain.DeviceType;
import com.grj.park.boot.service.DeviceTypeService;
import com.grj.park.boot.mapper.DeviceTypeMapper;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.grj.park.boot.util.StringUtil;
import org.springframework.security.core.context.SecurityContextHolder;
import java.util.HashMap;
import java.util.Map;

/**
 * @author eren
 * @description 针对表【device_type】的数据库操作Service实现
 * @createDate 2024-10-21 15:45:24
 */
@Service
public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceType> implements DeviceTypeService {

    @Override
    public Page<DeviceType> fetchDeviceTypePage(int currentPage, int pageSize, DeviceType deviceType, List<LocalDateTime> during) {
        QueryWrapper<DeviceType> deviceTypeQueryWrapper = Wrappers.query();
        if (during != null && !during.isEmpty()) {
            deviceTypeQueryWrapper.between("create_time", during.get(0), during.get(1));
        }
        Map<String, Object> stringObjectMap = BeanUtil.beanToMap(deviceType);
        HashMap<String, Object> map = new HashMap<>();
        stringObjectMap.forEach((k, v) -> {
            if (v != null) {
                map.put(StringUtil.toCamelCase(k), v);
            }
        });
        deviceTypeQueryWrapper.allEq(map, false);
        return baseMapper.selectPage(new Page<>(currentPage, pageSize), deviceTypeQueryWrapper);
    }

    @Override
    public void postDeviceType(DeviceType deviceType) {
        baseMapper.insert(deviceType);
    }

    @Override
    public void putDeviceType(DeviceType deviceType) {
        baseMapper.updateById(deviceType);
    }

    @Override
    public void delDeviceType(Long id) {
        baseMapper.deleteById(id);
    }

    @Override
    public void batchDelDeviceType(List<Long> ids) {
        System.out.println(ids);
        baseMapper.deleteBatchIds(ids);
    }

    @Override
    public DeviceType fetchDeviceTypeById(Long id) {
        return baseMapper.selectById(id);
    }

}





